using System;
using System.Collections.Generic;
using System.Text;

using SharpMUD.Framework.CorlibExtensions;

namespace SharpMUD.Framework.IO
{
    public class ByteQueueTextWriter : System.IO.TextWriter
    {
        private Queue<byte> _ByteQueue;
        private System.Text.Encoding _TextEncoding;

        private ByteQueueTextWriter() { }
        public ByteQueueTextWriter(Queue<byte> byteQueue, System.Text.Encoding textEncoding)
        {
            this._ByteQueue = byteQueue;
            this._TextEncoding = textEncoding;
        }

        public override string NewLine
        {
            get
            {
                return base.NewLine;
            }
            set
            {
                base.NewLine = value;
            }
        }

        #region Writes
        public override void Write(char[] buffer)
        {
            this._ByteQueue.Enqueue(this.Encoding.GetBytes(buffer));
        }
        public override void Write(bool value)
        {
            this.Write(value.ToString());
        }
        public override void Write(char value)
        {
            this.Write(value.ToString());
        }
        public override void Write(decimal value)
        {
            this.Write(value.ToString());
        }
        public override void Write(double value)
        {
            this.Write(value.ToString());
        }
        public override void Write(int value)
        {
            this.Write(value.ToString());
        }
        public override void Write(long value)
        {
            this.Write(value.ToString());
        }
        public override void Write(object value)
        {
            this.Write(value.ToString());
        }
        public override void Write(float value)
        {
            this.Write(value.ToString());
        }
        public override void Write(string value)
        {
            this._ByteQueue.Enqueue(this.Encoding.GetBytes(value));
        }
        [CLSCompliant(false)]
        public override void Write(uint value)
        {
            this.Write(value.ToString());
        }
        [CLSCompliant(false)]
        public override void Write(ulong value)
        {
            this.Write(value.ToString());
        }
        public override void Write(string format, object arg0)
        {
            this.Write(String.Format(format, arg0));
        }
        public override void Write(char[] buffer, int index, int count)
        {
            this._ByteQueue.Enqueue(this.Encoding.GetBytes(buffer, index, count));
        }
        public override void Write(string format, object arg0, object arg1)
        {
            this.Write(String.Format(format, arg0, arg1));
        }
        public override void Write(string format, object arg0, object arg1, object arg2)
        {
            this.Write(String.Format(format, arg0, arg1, arg2));
        }
        public override void WriteLine()
        {
            this.Write(this.NewLine);
        }
        public override void WriteLine(char value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(char[] buffer)
        {
            this._ByteQueue.Enqueue(this.Encoding.GetBytes(buffer));
            this.WriteLine();
        }
        public override void WriteLine(bool value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(decimal value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(double value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(int value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(long value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(object value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(float value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(string value)
        {
            this.Write(value + this.NewLine);
        }
        [CLSCompliant(false)]
        public override void WriteLine(uint value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        [CLSCompliant(false)]
        public override void WriteLine(ulong value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(string format, object arg0)
        {
            this.Write(String.Format(format, arg0) + this.NewLine);
        }
        public override void WriteLine(string format, object arg0, object arg1)
        {
            this.Write(String.Format(format, arg0, arg1) + this.NewLine);
        }
        public override void WriteLine(char[] buffer, int index, int count)
        {
            this._ByteQueue.Enqueue(this.Encoding.GetBytes(buffer, index, count));
            this.WriteLine();
        }
        public override void WriteLine(string format, object arg0, object arg1, object arg2)
        {
            this.Write(String.Format(format, arg0, arg1, arg2));
        }

        #endregion

        public override Encoding Encoding
        {
            get { return this._TextEncoding; }
        }
    }

    public class CharQueueTextWriter : System.IO.TextWriter
    {
        private Queue<char> _CharQueue;
        private System.Text.Encoding _TextEncoding;

        private CharQueueTextWriter() { }
        public CharQueueTextWriter(Queue<char> byteQueue, System.Text.Encoding textEncoding)
        {
            this._CharQueue = byteQueue;
            this._TextEncoding = textEncoding;
        }

        public override string NewLine
        {
            get
            {
                return base.NewLine;
            }
            set
            {
                base.NewLine = value;
            }
        }

        #region Writes
        public override void Write(char[] buffer)
        {
            this._CharQueue.Enqueue(buffer);
        }
        public override void Write(bool value)
        {
            this.Write(value.ToString());
        }
        public override void Write(char value)
        {
            this.Write(value.ToString());
        }
        public override void Write(decimal value)
        {
            this.Write(value.ToString());
        }
        public override void Write(double value)
        {
            this.Write(value.ToString());
        }
        public override void Write(int value)
        {
            this.Write(value.ToString());
        }
        public override void Write(long value)
        {
            this.Write(value.ToString());
        }
        public override void Write(object value)
        {
            this.Write(value.ToString());
        }
        public override void Write(float value)
        {
            this.Write(value.ToString());
        }
        public override void Write(string value)
        {
            this._CharQueue.Enqueue(value.ToCharArray());
        }
        [CLSCompliant(false)]
        public override void Write(uint value)
        {
            this.Write(value.ToString());
        }
        [CLSCompliant(false)]
        public override void Write(ulong value)
        {
            this.Write(value.ToString());
        }
        public override void Write(string format, object arg0)
        {
            this.Write(String.Format(format, arg0));
        }
        public override void Write(char[] buffer, int index, int count)
        {
            for (int x = 0; x < count; x++)
            {
                this._CharQueue.Enqueue(buffer[index + x]);
            }
        }
        public override void Write(string format, object arg0, object arg1)
        {
            this.Write(String.Format(format, arg0, arg1));
        }
        public override void Write(string format, object arg0, object arg1, object arg2)
        {
            this.Write(String.Format(format, arg0, arg1, arg2));
        }
        public override void WriteLine()
        {
            this.Write(this.NewLine);
        }
        public override void WriteLine(char value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(char[] buffer)
        {
            this._CharQueue.Enqueue(buffer);
            this.WriteLine();
        }
        public override void WriteLine(bool value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(decimal value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(double value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(int value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(long value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(object value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(float value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(string value)
        {
            this.Write(value + this.NewLine);
        }
        [CLSCompliant(false)]
        public override void WriteLine(uint value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        [CLSCompliant(false)]
        public override void WriteLine(ulong value)
        {
            this.Write(value.ToString() + this.NewLine);
        }
        public override void WriteLine(string format, object arg0)
        {
            this.Write(String.Format(format, arg0) + this.NewLine);
        }
        public override void WriteLine(string format, object arg0, object arg1)
        {
            this.Write(String.Format(format, arg0, arg1) + this.NewLine);
        }
        public override void WriteLine(char[] buffer, int index, int count)
        {
            for (int x = 0; x < count; x++)
            {
                this._CharQueue.Enqueue(buffer[index + x]);
            }
            this.WriteLine();
        }
        public override void WriteLine(string format, object arg0, object arg1, object arg2)
        {
            this.Write(String.Format(format, arg0, arg1, arg2));
        }

        #endregion

        public override Encoding Encoding
        {
            get { return this._TextEncoding; }
        }
    }
}
